package zhh.tangbao.machine.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import zhh.tangbao.system.constant.CommonConstant;
import zhh.tangbao.system.utils.RedisUtil;

/**
 * <p>
 * 通过与Redis连接实现
 * </p>
 * @author 粥灰灰
 * <p>2023/3/27</p>
 */

@Component
public class MachineHolderUtil {

    @Autowired
    private RedisUtil util;

    public void addMachineKV(String acode, String machineId) {
        util.set(getKey(acode), machineId, true);
    }

    public String getMachineId(String acode) {
        String key = getKey(acode);
        Object o = util.get(key);
        return String.valueOf(o);
    }

    public void remove(String acode) {
        util.del(getKey(acode));
    }

    private String getKey(String key) {
        return CommonConstant.REDIS_MACHINE + key;
    }
}
